package com.goods.business.service.imp;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.goods.business.mapper.ProductCategoryMapper;
import com.goods.business.service.ProductCategoryService;
import com.goods.common.enums.system.UserTypeEnum;
import com.goods.common.model.business.Category;
import com.goods.common.model.system.Department;
import com.goods.common.model.system.User;
import com.goods.common.vo.business.ProductCategoryTreeNodeVO;
import com.goods.common.vo.business.ProductCategoryVO;


import com.goods.common.vo.system.DepartmentVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

/**
 * @author gjl
 * @create 2021-06-07 14:48
 */
@Service
public class ProductCategoryServiceImpl implements ProductCategoryService {
    @Autowired
    private ProductCategoryMapper productCategoryMapper;

    //查询所有物资信息
    @Override
    public PageVO<ProductCategoryTreeNodeVO> getList(Integer pageNum, Integer pageSize, ProductCategoryTreeNodeVO productCategoryTreeNodeVO) {

        List<Category> categories = productCategoryMapper.selectAll();
        ArrayList<ProductCategoryTreeNodeVO> categoryVOS = new ArrayList<>();
        if (!CollectionUtils.isEmpty(categories)) {
            for (Category category : categories) {
                ProductCategoryTreeNodeVO vo = new ProductCategoryTreeNodeVO();
                BeanUtils.copyProperties(category,vo);
                categoryVOS.add(vo);
            }
        }
        
        PageInfo<Category> info = new PageInfo<>(categories);
        return new PageVO<>(info.getTotal(),categoryVOS);
    }
}
